package com.yfl.logistics.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yfl.logistics.pojo.Permission;
import com.yfl.logistics.mapper.PermissionMapper;
import com.yfl.logistics.pojo.Role;
import com.yfl.logistics.service.IPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-06-13
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements IPermissionService {

    @Autowired
    private RoleServiceImpl roleService;

    @Override
    public IPage<Permission> selectPermission(IPage iPage, QueryWrapper wrapper) {
        return baseMapper.selectPermission(iPage,wrapper);
    }

    @Override
    public List<String> selectRolePermissionIds(Long roleId) {
        //获取角色拥有的权限id
        QueryWrapper<Role> wrapper=new QueryWrapper<>();
        wrapper.eq("role_id",roleId);
        Role role = roleService.getOne(wrapper);
        List<String> expression = baseMapper.selectRoleExpression(role.getPermissionIds());

        return expression;
    }
}
